package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsSeniorSearchMapper;
import net.anzhuo.entity.GsSeniorSearch;
import net.anzhuo.service.GsSeniorSearchService;
@Service
public class GsSeniorSearchServiceImpl implements GsSeniorSearchService {

	@Autowired
	private GsSeniorSearchMapper gsSeniorSearchMapper;
	
	@Override
	public GsSeniorSearch getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsSeniorSearchMapper.getById(id);
	}

	@Override
	public List<GsSeniorSearch> getBytypeCode(String typeCode) {
		// TODO Auto-generated method stub
		return gsSeniorSearchMapper.getBytypeCode(typeCode);
	}

	@Override
	public PaginationVO<GsSeniorSearch> getListWithPage(GsSeniorSearch gsSeniorSearch) {
		PaginationVO<GsSeniorSearch> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsSeniorSearchMapper.getListWithPage(gsSeniorSearch));
		paginationVO.setTotalCount(gsSeniorSearchMapper.getCount(gsSeniorSearch.getTypeCode()));
		paginationVO.setTotalPage((gsSeniorSearchMapper.getCount(gsSeniorSearch.getTypeCode())-1)  / gsSeniorSearch.getPageSize()+1);
		paginationVO.setPageNo(gsSeniorSearch.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsSeniorSearch> getList() {
		// TODO Auto-generated method stub
		return  gsSeniorSearchMapper.getList();
	}

	@Override
	public List<GsSeniorSearch> getList(GsSeniorSearch gsSeniorSearch) {
		// TODO Auto-generated method stub
		return gsSeniorSearchMapper.getListByQuery(gsSeniorSearch);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsSeniorSearch gsSeniorSearch) {
		// TODO Auto-generated method stub
		gsSeniorSearchMapper.update(gsSeniorSearch);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsSeniorSearch gsSeniorSearch) {
		// TODO Auto-generated method stub
		gsSeniorSearchMapper.save(gsSeniorSearch);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsSeniorSearch gsSeniorSearch = gsSeniorSearchMapper.getById(id);
		if (gsSeniorSearch == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsSeniorSearchMapper.update(gsSeniorSearch);

	}

}
